import socket

# 创建一个UDP socket
udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

# 监听的广播地址和端口
broadcast_address = ''
broadcast_port = 9999

# 绑定socket到广播地址和端口
udp_socket.bind((broadcast_address, broadcast_port))

# 接收数据
while True:
    data, address = udp_socket.recvfrom(1024)
    print(f"Received message from {address}: {data.decode()}")

# 关闭socket
udp_socket.close()